x = int(input())
m = 0
c = 0
c1 = 0
c2 = 0
c3 = 0
c4 = 0
c5= 0
c6= 0
c7= 0
c8= 0
c9= 0
c10= 0
c11 = 0
c12 = 0
c13 = 0
c14 = 0
e = x % 10 # 5
d = x // 10 # 173
ee = d % 10 # 3
dd = d // 10 # 17
eee = dd % 10 # 7
ddd = dd // 10 # 1
k1 = eee * 100 + ee * 10 + e
k2 = ddd * 100 + ee * 10 + e
k3 = ddd * 100 + eee * 10 + e
k4 = ddd * 100 + eee * 10 + ee
k5 = ee * 10 + e
k6 = eee * 10 + e
k7 = eee * 10 + ee
k8 = ddd * 10 + e
k9 = ddd * 10 + ee
k10 = ddd * 10 + eee
k11 = ddd
k12 = eee
k13 = ee
k14 = e
if len(str(x)) != 4 or x < 0:
  print(0)
else:
  for i in range(1, x+1):
    if  x % i == 0 :
     c = c + 1
  if c == 2:
    if m < x:
      m = x
  for i in range(1, k1+1):
    if  k1 % i == 0 :
     c1 = c1 + 1
  if c1 == 2:
    if m < k1:
      m = k1
  for i in range(1, k2+1):
    if  k2 % i == 0 :
     c2 = c2 + 1
  if c2 == 2:
    if m < k2:
      m = k2
  for i in range(1, k3+1):
    if  k3 % i == 0 :
     c3 = c3 + 1
  if c3 == 2:
    if m < k3:
      m = k3
  for i in range(1, k4+1):
    if  k4 % i == 0 :
     c4 = c4 + 1
  if c4 == 2:
    if m < k4:
      m = k4
  for i in range(1, k5+1):
    if  k5 % i == 0 :
     c5 = c5 + 1
  if c5 == 2:
    if m < k5:
      m = k5
  for i in range(1, k6+1):
    if  k6 % i == 0 :
     c6 = c6 + 1
  if c6 == 2:
    if m < k6:
      m = k6
  for i in range(1, k7+1):
    if  k7 % i == 0 :
     c7 = c7 + 1
  if c7 == 2:
    if m < k7:
      m = k7
  for i in range(1, k8+1):
    if  k8 % i == 0 :
     c8 = c8 + 1
  if c8 == 2:
    if m < k8:
      m = k8
  for i in range(1, k9+1):
    if  k9 % i == 0 :
     c9 = c9 + 1
  if c9 == 2:
    if m < k9:
      m = k9
  for i in range(1, k10+1):
    if  k10 % i == 0 :
     c10 = c10 + 1
  if c10 == 2:
    if m < k10:
      m = k10
  for i in range(1, k11+1):
    if  k11 % i == 0 :
     c11 = c11 + 1
  if c11 == 2:
    if m < k11:
      m = k11
  for i in range(1, k12+1):
    if  k12 % i == 0 :
     c12 = c12 + 1
  if c12 == 2:
    if m < k12:
      m = k12
  for i in range(1, k13+1):
    if  k13 % i == 0 :
     c13 = c13 + 1
  if c13 == 2:
    if m < k13:
      m = k13
  for i in range(1, k14+1):
    if  k14 % i == 0 :
     c14 = c14 + 1
  if c14 == 2:
    if m < k14:
      m = k14
  print(m)
